package com.slm.krstartimes.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.slm.krstartimes.R;
import com.slm.krstartimes.adapter.RelatedListAdapter;
import com.slm.krstartimes.db.sqlite.SQLiteDataBaseManager;
import com.slm.krstartimes.db.sqlite.SQLiteDataBaseTools;
import com.slm.krstartimes.utils.FormatCodeUtil;
import com.slm.krstartimes.utils.L;
import com.slm.krstartimes.utils.MyStringRequest;
import com.slm.krstartimes.utils.Myanim;
import com.slm.krstartimes.utils.News;
import com.slm.krstartimes.utils.NewsDetialSAX;
import com.slm.krstartimes.utils.StreamRequest;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.bean.SocializeEntity;
import com.umeng.socialize.controller.UMServiceFactory;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.controller.listener.SocializeListeners;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.sso.QZoneSsoHandler;
import com.umeng.socialize.sso.SinaSsoHandler;
import com.umeng.socialize.sso.UMQQSsoHandler;
import com.umeng.socialize.sso.UMSsoHandler;
import com.umeng.socialize.weixin.controller.UMWXHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

/**
 * Created by dllo on 15/8/5.
 */
public class NewsDetailActivity extends Activity implements View.OnTouchListener, GestureDetector.OnGestureListener {
    final UMSocialService mController = UMServiceFactory.getUMSocialService("com.umeng.share");
    List<News> list;
    int totalHeight = 0;
    private String url = null;
    private String newsId;
    private Handler handler;
    private boolean areButtonsShowing;
    private RelativeLayout composerButtonsWrapper;
    private ImageView composerButtonsShowHideButtonIcon, startTTS;
    private RelativeLayout composerButtonsShowHideButton;
    private TextView title, postDate, newsSource, newsAuthor, hitCount;
    private SQLiteDataBaseTools sqLiteDataBaseTools;
    private WebView newsDetail;
    private RelatedListAdapter relatedListAdapter;
    private ListView correlation;
    private TextToSpeech speech;
    private GestureDetector myGestureDetector;
    private int verticalMinDistance = 50;
    private int middleDistance = 80;
    private int minVelocity = 0;
    private FrameLayout frameLayout;
    private RequestQueue requestQueue;
    private Intent intent;
    private ImageButton qq, qqzone, sina, friendcycle, collect;
    private SharedPreferences preferences;
    private SharedPreferences.Editor editor;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.news_detial);// 加载布局

        sqLiteDataBaseTools = new SQLiteDataBaseTools(this);
        initView();// 初始化
        speech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int i) {
                if (i == TextToSpeech.SUCCESS) {
                    int supported = speech.setLanguage(Locale.CHINA);
                }
            }
        });
        firstGuider();// 第一次启动

        frameLayout.setOnTouchListener(this);// 为整个页面设置触摸监听
        frameLayout.setLongClickable(true);
        myGestureDetector = new GestureDetector(this);

        intent = getIntent();// 定义一个intent接收对象,获取id等数据

        newsId = intent.getStringExtra("newsId");// 得到id
        title.setText(intent.getStringExtra("title"));
        getDetail(newsId, intent);// 调用网络请求

        Share(newsId);// 分享

        satelliteMenu();// 卫星菜单

    }

    private void satelliteMenu() {
    /*卫星菜单*/
        composerButtonsShowHideButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<News> temp = sqLiteDataBaseTools.queryById(SQLiteDataBaseManager.LIKE, intent.getStringExtra("newsId"));
                if (temp.size() > 0) {
                    collect.setSelected(true);
                }
                if (!areButtonsShowing) {
                    Myanim.startAnimationsIn(composerButtonsWrapper, 300);
                    composerButtonsShowHideButtonIcon
                            .startAnimation(Myanim.getRotateAnimation(0,
                                    -225, 300));
                } else {
                    Myanim
                            .startAnimationsOut(composerButtonsWrapper, 300);
                    composerButtonsShowHideButtonIcon
                            .startAnimation(Myanim.getRotateAnimation(
                                    -225, 0, 300));
                }
                areButtonsShowing = !areButtonsShowing;
            }
        });
        for (int i = 0; i < composerButtonsWrapper.getChildCount(); i++) {
            composerButtonsWrapper.getChildAt(i).setOnClickListener(
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {

                            switch (v.getId()) {
                                case R.id.friendcycle:
                                    WEIXINshare(newsId);
                                    break;
                                case R.id.qq:
                                    QQshare();
                                    break;
                                case R.id.qqzone:
                                    QQzoneshare();
                                    break;
                                case R.id.xinlang:
                                    SINAshare();
                                    break;
                                case R.id.collect:
                                    collect();
                                    break;


                            }
                        }
                    });
        }
    }

    /**
     * 第一次启动显示引导
     */
    private void firstGuider() {
        preferences = getSharedPreferences("guider", Context.MODE_PRIVATE);
        if (preferences.getBoolean("firstStart", true)) {
            editor = preferences.edit();
            editor.putBoolean("firstStart", false);
            editor.commit();
            Intent guider = new Intent(this, GuiderActivity.class);
            startActivity(guider);
        }
    }

    /**
     * 初始化
     */
    private void initView() {
        correlation = (ListView) findViewById(R.id.correlation);//实例化组件
        Myanim.initOffset(NewsDetailActivity.this);
        requestQueue = Volley.newRequestQueue(this);
        composerButtonsWrapper = (RelativeLayout) findViewById(R.id.composer_buttons_wrapper);
        composerButtonsShowHideButton = (RelativeLayout) findViewById(R.id.composer_buttons_show_hide_button);
        composerButtonsShowHideButtonIcon = (ImageView) findViewById(R.id.composer_buttons_show_hide_button_icon);
        frameLayout = (FrameLayout) findViewById(R.id.total);
        startTTS = (ImageView) findViewById(R.id.startTTS);
        title = (TextView) findViewById(R.id.title);


        qq = (ImageButton) findViewById(R.id.qq);
        qqzone = (ImageButton) findViewById(R.id.qqzone);
        friendcycle = (ImageButton) findViewById(R.id.friendcycle);
        sina = (ImageButton) findViewById(R.id.xinlang);
        collect = (ImageButton) findViewById(R.id.collect);

        postDate = (TextView) findViewById(R.id.postDate);
        newsSource = (TextView) findViewById(R.id.newsSource);
        newsAuthor = (TextView) findViewById(R.id.newsAuthor);
        hitCount = (TextView) findViewById(R.id.hitCount);
        newsDetail = (WebView) findViewById(R.id.newsDetail);
    }

    /**
     * 网络拉取
     *
     * @param newsId 新闻id
     * @param intent intent对象
     */
    private void getDetail(String newsId, final Intent intent) {
        String id1 = newsId.substring(0, 3);// 分割id,用于拼接到地址中
        String id2 = newsId.substring(3, 6);
        L.v("传入的新闻ID", id1 + "/" + id2);
        StreamRequest request = new StreamRequest("http://api.ithome.com/xml/newscontent/" + id1 + "/" + id2 + ".xml",
                new Response.Listener<InputStream>() {
                    /**
                     * 请求成功,显示到WebView
                     * @param inputStream
                     */
                    @Override
                    public void onResponse(InputStream inputStream) {
                        /*接收解析完成的数据并显示到WebView*/
                        handler = new Handler(new Handler.Callback() {
                            @Override
                            public boolean handleMessage(Message message) {
                                if (message.what == 100) {
                                    list = (List<News>) message.obj;
                                    for (News news : list) {

                                        title.setText(intent.getStringExtra("title"));
                                        postDate.setText(intent.getStringExtra("postdate"));
                                        newsSource.setText(news.getNewssource());
                                        newsAuthor.setText(news.getNewsauthor());
                                        hitCount.setText(intent.getStringExtra("hitCount"));
                                        Document doc_Dis = Jsoup.parse(news.getDetail());
                                        Elements ele_Img = doc_Dis.getElementsByTag("img");
                                        if (ele_Img.size() != 0) {
                                            for (Element e_Img : ele_Img) {
                                                e_Img.attr("style", "width:100%");
                                            }
                                        }
                                        final String newHtmlContent = doc_Dis.toString();
                                        startTTS.setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                speech.setLanguage(Locale.CHINESE);
                                                speech.speak(newHtmlContent, TextToSpeech.QUEUE_FLUSH, null);
                                            }
                                        });

                                        newsDetail.loadDataWithBaseURL("about:blank", newHtmlContent, "text/html", "utf-8", null);// 显示到WebView
                                        WebSettings settings = newsDetail.getSettings();
                                        settings.setJavaScriptEnabled(true);
                                        settings.setJavaScriptCanOpenWindowsAutomatically(true);

                                        newsDetail.setOnTouchListener(new View.OnTouchListener() {
                                            @Override
                                            public boolean onTouch(View view, MotionEvent motionEvent) {

                                                return false;
                                            }
                                        });

                                        String newTag = FormatCodeUtil.codingFormat(news.getTags());//新闻关键字进行转码,拼接到相关新闻的地址中

                                        /*请求相关新闻列表的request*/
                                        MyStringRequest stringRequest = new MyStringRequest("http://www.ithome.com/json/tags/" + newTag + ".json",
                                                new Response.Listener<String>() {
                                                    @Override
                                                    public void onResponse(String s) {

                                                        if (s != null && s.length() > 2) {
                                                            String[] temp = s.split("=");//对拉取到的json数据进行规范操作,便于解析
                                                            Gson gson = new Gson();// 实例化gson对象
                                                            Type type = new TypeToken<ArrayList<News>>() {
                                                            }.getType();
                                                            final List<News> vartag_jsonp = gson.fromJson(temp[1], type);// 利用gson解析JSON数组

                                                            relatedListAdapter = new RelatedListAdapter(NewsDetailActivity.this, vartag_jsonp);// 实例化适配器

                                                            correlation.setAdapter(relatedListAdapter);//设置到适配器

                                                            for (int i = 0, len = relatedListAdapter.getCount(); i < len; i++) { // listAdapter.getCount()返回数据项的数目
                                                                View listItem = relatedListAdapter.getView(i, null, correlation);
                                                                listItem.measure(0, 0); // 计算子项View 的宽高
                                                                totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
                                                            }
                                                            ViewGroup.LayoutParams params = correlation.getLayoutParams();
                                                            params.height = totalHeight + (correlation.getDividerHeight() * (relatedListAdapter.getCount()));
                                                            correlation.setLayoutParams(params);

                                                            correlation.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                                                                /*监听相关新闻列表*/
                                                                @Override
                                                                public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                                                                    Intent newsDetail = new Intent(NewsDetailActivity.this, NewsDetailActivity.class);// 新建intent对象,跳转本身
                                                                    newsDetail.putExtra("newsId", vartag_jsonp.get(i).getNewsid());//向目标传递数据
                                                                    newsDetail.putExtra("title", vartag_jsonp.get(i).getNewstitle());
                                                                    newsDetail.putExtra("postdate", vartag_jsonp.get(i).getPostdate());
                                                                    startActivity(newsDetail);// 开始跳转
                                                                }
                                                            });
                                                        }
                                                    }
                                                }, new Response.ErrorListener() {
                                            @Override
                                            public void onErrorResponse(VolleyError volleyError) {

                                            }
                                        });
                                        requestQueue.add(stringRequest);
                                    }

                                }
                                return false;
                            }
                        });
                        /*将获取成功的数据调用xml解析方法进行解析*/
                        SAXParserFactory spx = SAXParserFactory.newInstance();
                        try {
                            SAXParser sp = spx.newSAXParser();
                            sp.parse(inputStream, new NewsDetialSAX(handler));

                        } catch (ParserConfigurationException e) {
                            e.printStackTrace();
                        } catch (SAXException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.i("网络拉取成功", volleyError.toString());
            }
        });

//        String newTag = FormatCodeUtil.codingFormat(list.get(0).getTags());


        requestQueue.add(request);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        newsDetail.reload();// 销毁时重新加载
        speech.shutdown();// 销毁时关闭TTS
    }


    @Override
    public boolean onDown(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent motionEvent) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent motionEvent) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float v, float v1) {

        return false;
    }

    @Override
    public void onLongPress(MotionEvent motionEvent) {

    }

    /**
     * 滑动手势响应
     *
     * @param e1
     * @param e2
     * @param v
     * @param v1
     * @return
     */
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float v, float v1) {
        if (e2.getX() - e1.getX() > middleDistance && Math.abs(v) > minVelocity && (Math.abs(e2.getY() - e1.getY()) < verticalMinDistance)) {
            finish();
        } else if (e1.getX() - e2.getX() > middleDistance && Math.abs(v) > minVelocity && (Math.abs(e2.getY() - e1.getY()) < verticalMinDistance)) {
            Intent comment = new Intent(this, CommentActivity.class);
            comment.putExtra("newsId", intent.getStringExtra("newsId"));
            startActivity(comment);
        } else if (e1.getY() - e2.getY() > minVelocity) {
            composerButtonsWrapper.setVisibility(View.INVISIBLE);
            composerButtonsShowHideButton.setVisibility(View.INVISIBLE);
            startTTS.setVisibility(View.INVISIBLE);
            Animation animation1 = AnimationUtils.loadAnimation(this, R.anim.alpha_a_short);
            composerButtonsWrapper.setAnimation(animation1);
            composerButtonsShowHideButton.setAnimation(animation1);
            startTTS.setAnimation(animation1);
        } else if (e2.getY() - e1.getY() > minVelocity) {
            composerButtonsWrapper.setVisibility(View.VISIBLE);
            composerButtonsShowHideButton.setVisibility(View.VISIBLE);
            startTTS.setVisibility(View.VISIBLE);
            Animation animation2 = AnimationUtils.loadAnimation(this, R.anim.alpha_b_short);
            composerButtonsWrapper.setAnimation(animation2);
            composerButtonsShowHideButton.setAnimation(animation2);
            startTTS.setAnimation(animation2);
        }
        return false;
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return myGestureDetector.onTouchEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        myGestureDetector.onTouchEvent(ev);
        // scroll.onTouchEvent(ev);
        return super.dispatchTouchEvent(ev);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**使用SSO授权必须添加如下代码 */
        UMSsoHandler ssoHandler = mController.getConfig().getSsoHandler(requestCode);
        if (ssoHandler != null) {
            ssoHandler.authorizeCallBack(requestCode, resultCode, data);
        }

    }

    /**
     * 分享
     *
     * @param newsId
     */
    public void Share(String newsId) {


        mController.setShareContent("氪星时代  我们的时代 " + "http://wap.ithome.com/html/" + newsId + ".htm");

        UMQQSsoHandler qqSsoHandler = new UMQQSsoHandler(NewsDetailActivity.this, "100424468",
                "c7394704798a158208a74ab60104f0ba");
        qqSsoHandler.addToSocialSDK();

        String appId = "wx967daebe835fbeac";
        String appSecret = "5fa9e68ca3970e87a1f83e563c8dcbce";
        // 添加微信平台
        UMWXHandler wxHandler = new UMWXHandler(NewsDetailActivity.this, appId, appSecret);
        wxHandler.addToSocialSDK();
        // 添加微信朋友圈
        UMWXHandler wxCircleHandler = new UMWXHandler(NewsDetailActivity.this, appId, appSecret);
        wxCircleHandler.setToCircle(true);
        wxCircleHandler.addToSocialSDK();

        //参数1为当前Activity，参数2为开发者在QQ互联申请的APP ID，参数3为开发者在QQ互联申请的APP kEY.
        QZoneSsoHandler qZoneSsoHandler = new QZoneSsoHandler(NewsDetailActivity.this, "100424468",
                "c7394704798a158208a74ab60104f0ba");
        qZoneSsoHandler.addToSocialSDK();
        QZoneShareContent qzone = new QZoneShareContent();
        //设置分享文字
        qzone.setShareContent("氪星时代 我们的时代");
        //设置点击消息的跳转URL
        qzone.setTargetUrl("http://wap.ithome.com/html/" + newsId + ".htm");


        mController.setShareMedia(qzone);
        QQShareContent qqShareContent = new QQShareContent();
//设置分享文字
        qqShareContent.setShareContent("氪星时代 我们的时代");

//设置点击分享内容的跳转链接
        qqShareContent.setTargetUrl("http://wap.ithome.com/html/" + newsId + ".htm");
        mController.setShareMedia(qqShareContent);

        //设置新浪SSO handler
        mController.getConfig().setSsoHandler(new SinaSsoHandler());


    }

    /**
     * 微信分享
     *
     * @param newsId
     */
    private void WEIXINshare(String newsId) {
        CircleShareContent circleMedia = new CircleShareContent();

        circleMedia.setTargetUrl("http://wap.ithome.com/html/" + newsId + ".htm");
        mController.setShareMedia(circleMedia);


        mController.postShare(NewsDetailActivity.this, SHARE_MEDIA.WEIXIN,
                new SocializeListeners.SnsPostListener() {
                    @Override
                    public void onStart() {
                        Toast.makeText(NewsDetailActivity.this, "开始分享.", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) {
                        if (eCode == 200) {
                            Toast.makeText(NewsDetailActivity.this, "分享成功.", Toast.LENGTH_SHORT).show();
                        } else {
                            String eMsg = "";
                            if (eCode == -101) {
                                eMsg = "没有授权";
                            }
                            Toast.makeText(NewsDetailActivity.this, "分享失败[" + eCode + "] " +
                                    eMsg, Toast.LENGTH_SHORT).show();
                        }
                    }
                });

    }

    /**
     * QQ分享
     */
    private void QQshare() {
        mController.postShare(NewsDetailActivity.this, SHARE_MEDIA.QQ,
                new SocializeListeners.SnsPostListener() {
                    @Override
                    public void onStart() {
                        Toast.makeText(NewsDetailActivity.this, "开始分享.", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) {
                        if (eCode == 200) {
                            Toast.makeText(NewsDetailActivity.this, "分享成功.", Toast.LENGTH_SHORT).show();
                            L.i("分享成功");
                        } else {
                            String eMsg = "";
                            if (eCode == -101) {
                                eMsg = "没有授权";
                            }
                            Toast.makeText(NewsDetailActivity.this, "分享失败[" + eCode + "] " +
                                    eMsg, Toast.LENGTH_SHORT).show();
                            L.i("分享失败," + eCode + eMsg);
                        }
                    }
                });
    }

    /**
     * 分享QQ空间
     */
    private void QQzoneshare() {
        mController.postShare(NewsDetailActivity.this, SHARE_MEDIA.QZONE,
                new SocializeListeners.SnsPostListener() {
                    @Override
                    public void onStart() {
                        Toast.makeText(NewsDetailActivity.this, "开始分享.", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) {
                        if (eCode == 200) {
                            Toast.makeText(NewsDetailActivity.this, "分享成功.", Toast.LENGTH_SHORT).show();
                            L.i("分享成功");
                        } else {
                            String eMsg = "";
                            if (eCode == -101) {
                                eMsg = "没有授权";
                            }
                            Toast.makeText(NewsDetailActivity.this, "分享失败[" + eCode + "] " +
                                    eMsg, Toast.LENGTH_SHORT).show();
                            L.i("分享失败," + eCode + eMsg);
                        }
                    }
                });
    }

    /**
     * 分享微博
     */
    private void SINAshare() {
        mController.postShare(NewsDetailActivity.this, SHARE_MEDIA.SINA,
                new SocializeListeners.SnsPostListener() {
                    @Override
                    public void onStart() {
                        Toast.makeText(NewsDetailActivity.this, "开始分享.", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) {
                        if (eCode == 200) {
                            Toast.makeText(NewsDetailActivity.this, "分享成功.", Toast.LENGTH_SHORT).show();
                            L.i("分享成功");
                        } else {
                            String eMsg = "";
                            if (eCode == -101) {
                                eMsg = "没有授权";
                            }
                            Toast.makeText(NewsDetailActivity.this, "分享失败[" + eCode + "] " +
                                    eMsg, Toast.LENGTH_SHORT).show();
                            L.i("分享失败," + eCode + eMsg);
                        }
                    }
                });
    }

    /**
     * 收藏功能
     */
    private void collect() {
        List<News> temp = sqLiteDataBaseTools.queryById(SQLiteDataBaseManager.LIKE, intent.getStringExtra("newsId"));
        if (temp.size() == 0) {
            sqLiteDataBaseTools.insert(intent.getStringExtra("newsId"), intent.getStringExtra("title"),
                    intent.getStringExtra("image"),
                    intent.getStringExtra("hitCount"), intent.getStringExtra("postdate"), SQLiteDataBaseManager.LIKE);
            collect.setSelected(true);
            Toast.makeText(NewsDetailActivity.this, "收藏成功", Toast.LENGTH_SHORT).show();
            L.i("收藏成功");
        } else {
            sqLiteDataBaseTools.deleteById(SQLiteDataBaseManager.LIKE, intent.getStringExtra("newsId"));
            Toast.makeText(NewsDetailActivity.this, "取消收藏", Toast.LENGTH_SHORT).show();
            collect.setSelected(false);
            L.i("取消收藏");
        }
    }


}
